﻿using System;
using System.Runtime.InteropServices;

namespace ace_pso
{
    public class LngCallback
    {
        public static int MyCallback(IntPtr pLingoEnv, int nReserved, IntPtr pMyData)
        {
            // Lingo callback function to display the current iteration count

            var cb = new CallbackData();
            Marshal.PtrToStructure(pMyData, cb);

            int nIterations = -1;
            int nErr = lingo.LSgetCallbackInfoLng(pLingoEnv,
                                                  lingo.LS_IINFO_ITERATIONS_LNG, ref nIterations);
            if (nErr == lingo.LSERR_NO_ERROR_LNG && nIterations != cb.nIterations)
            {
                cb.nIterations = nIterations;
                //Console.WriteLine("Iteration count={0}", nIterations);
                //MessageBox.Show(string.Format("Iteration count={0}", nIterations));
            }

            Marshal.StructureToPtr(cb, pMyData, true);

            return 0;
        }
    }
}